package com.common.app.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView
import com.common.app.R


/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：30/6/2023
 *
 * 描述：
 *
 * 修订历史：
 *
 */
 class CommentImagesAdapter(context: Context, datas: List<String?>?) :
    RecyclerView.Adapter<RecyclerView.ViewHolder?>(){
    private val datas: List<String?>
    private val mContext: Context
    private val inflater: LayoutInflater

    init {

        // 如果数据为空,则抛出异常
        var datas = datas
        if (datas == null) {
            datas = ArrayList()
        }
        this.datas = datas
        mContext = context
        inflater = LayoutInflater.from(mContext)
    }

    override fun getItemCount(): Int {
        return datas.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(
            inflater.inflate(R.layout.item_comment_image_list, null)
        )
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        setCuViewItem(holder as ViewHolder, position)
    }

    /**
     * 蓝底项构造参数
     *
     * @param holder   持有类
     * @param position 项位置
     */
    private fun setCuViewItem(holder:ViewHolder, position: Int) {
        // 获取设置各控件参数
        val url = datas[position]
//        GlideUtils.load(mContext, url, viewHolder.icon)
        holder.mTotalRl.tag = position
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var mTotalRl: RelativeLayout
        var icon: ImageView

        init {
            mTotalRl = itemView.findViewById(R.id.item_comment_image_total)
            icon = itemView
                .findViewById<View>(R.id.item_comment_image) as ImageView
//            mTotalRl.setOnClickListener(this@CommentImagesAdapter)
        }
    }

    fun onClick(v: View) {
        val pos = v.tag as Int
//        if (listener != null) {
//            listener.onItemClick(v, pos, pos)
//        }
    }
}